<template>
<div>
<div id="menuContentdevicesingle" style="display:none;position: absolute; margin: 34px 68px;z-index: 1000000;">
<ul id="devicesingle" class="ztree"></ul>
 <!-- <input type="hidden" id="device_id" value=""> -->
</div>
</div>
</template>
<style>
/*@import '../../../../static/css/ztree/metroStyle.css';*/
</style>
<style  scoped>
 ul.ztree {
    
    border: 1px solid #617775;
    background: #f0f6e4;
    width: 300px;
    height: 360px;
    overflow-y: auto;
    overflow-x: auto;
}
.ztree {
    margin: 0;
    
    color: #333;
}
.ztree {
    margin: 0;
    padding: 5px;
    color: #333;
}
  ::-webkit-scrollbar {
            width: 6px;
            /*height: 6px;*/
        }
        /*正常情况下滑块的样式*/
      ::-webkit-scrollbar-thumb {
            background-color: rgba(0,0,0,.05);
            border-radius: 10px;
            -webkit-box-shadow: inset 1px 1px 0 rgba(0,0,0,.1);
        }
        /*鼠标悬浮在该类指向的控件上时滑块的样式*/
        :hover::-webkit-scrollbar-thumb {
            background-color: rgba(0,0,0,.2);
            border-radius: 10px;
            -webkit-box-shadow: inset 1px 1px 0 rgba(0,0,0,.1);
        }
        /*鼠标悬浮在滑块上时滑块的样式*/
       ::-webkit-scrollbar-thumb:hover {
            background-color: rgba(0,0,0,.4);
            -webkit-box-shadow: inset 1px 1px 0 rgba(0,0,0,.1);
        }
        /*正常时候的主干部分*/
        ::-webkit-scrollbar-track {
            border-radius: 10px;
            -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0);
            background-color: white;
        }
        /*鼠标悬浮在滚动条上的主干部分*/
        ::-webkit-scrollbar-track:hover {
            -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.4);
            background-color: rgba(0,0,0,.01);
        }
       
</style>
<script>
	window.showMenudevicesingle=function(thi) {
        devicesingletree();
			var cityObj = $(thi);
			var cityOffset = $(thi).offset();
		//	$("#menuContentdevicesingle").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
	$("#menuContentdevicesingle").slideDown("fast");
			$("body").bind("mousedown", onBodyDowndevicesingle);
		}
		window.hideMenudevicesingle=function() {
			$("#menuContentdevicesingle").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDowndevicesingle);
		}
		window.onBodyDowndevicesingle=function(event) {console.log(event.target.id);
         if(event.target.className=="confirm"){

             return;
          }
         //console.log(event.target.className);
			if (!(event.target.id == "menuBtn" || event.target.id == "menuContentdevicesingle" || $(event.target).parents("#menuContentdevicesingle").length>0)) {
				hideMenudevicesingle();
			}
		}

 window.singlezTreeBeforeClick=function(treeId, treeNode, clickFlag) {
     var check = isNaN(treeNode.id);
			if (!check) {
                 swal("OMG!", "请选择设备", "error");	
            return false;
            }else{
 	//var zTree = $.fn.zTree.getZTreeObj("devicesingle");
   
    // var  	nodes = zTree.getCheckedNodes(true);
 //var nodes=zTree.getSelectedNodes();
$("#device_id").val(treeNode.id);
//$("#device_name").val(treeNode.name);

     //alert(str);
//hideMenudevicesingle();
}
}
 var settingdev={   
     view:{
				dblClickExpand: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
             callback: {
            beforeClick: singlezTreeBeforeClick
        }
 }

window.devicesingletree=function(){
       $.ajax({
                type: 'POST',
                url: domain.testUrl+"/Threeinjection/DeviceManagement/queryCompanyandDevice",
                data: {"sessionid":sessionStorage.getItem("sid"),"coid":sessionStorage.getItem("coid")},
                datatype:"JSON",
                success: function (response) {   
                var obj = eval("("+response+")");
                   // console.log(response);
               $.fn.zTree.init($("#devicesingle"), settingdev, JSON.parse(obj.companyandDevice));
                }
  });
}
</script>